package zjf.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jboss.resteasy.client.ClientRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class OperationUtil {
	private final static Logger logger = LoggerFactory
			.getLogger(OperationUtil.class);
	private  static String strURL;
	static{
		strURL=GlobalSeterUtil.getString("restUrl");
	}
	private static OperationUtil instance = null;
	public static OperationUtil getInstance() {
		if (instance == null) {
			instance = new OperationUtil();
		}
		return instance;
	}
	/**
	 * 获取燃气云服务器接口数据
	 * 
	 * @param map
	 *            方法名 ，条件
	 * @return result 返回结果
	 */
	@SuppressWarnings("deprecation")
	public static String result(Map<String, Object> map) {
		String result = "";
		try {
			ClientRequest client = new ClientRequest(strURL);
			String jsonPara = JSON.toJSONString(map);
			logger.debug("param:"+jsonPara);
			// 对输入参数进行utf-8编码
			String encode_str = java.net.URLEncoder.encode(jsonPara, "utf-8");
			client.body("text/plain", encode_str);
			String returnmsg = client.postTarget(String.class);
			// 对返回结果进行uft-8解码
			result = java.net.URLDecoder.decode(returnmsg, "utf-8");
			logger.debug("out:"+result);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	public static void main(String[] args) {
//		OperationUtil.getInstance().saveConcentratorSign("9981508000141A52",0);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("func_name", "queryCliffordGoodsList");
		String result=result(map);
//		JSONObject jsonpara = JSONObject.parseObject(result);
		System.out.println(result);
		JSONObject jsonpara = JSONObject.parseObject(result);
		if(jsonpara!=null&&jsonpara.size()>0){
			JSONArray ary=JSON.parseArray(jsonpara.getString("dataList"));
			for(Object o:ary){
				JSONObject j = JSONObject.parseObject(o.toString());
				System.out.println(j.getString("zjfGood"));
				System.out.println(j.getString("zjfGoodsType"));
			}
		}
		
	}

}
